<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>编辑公告-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">公告 > 编辑公告</div>
	</div>
	<div id="content">
		<form action="__APP__/System/notice_list_edit" method="post" name="number_validate" id="password_validate" novalidate="novalidate" />
			<input type="hidden" name="action" value="edit">
			<input type="hidden" name="id" value="{$result['id']}">
			<input type="hidden" name="l_tid" value="{$tid}">
			<input type="hidden" name="l_type" value="{$type}">
			<div class="form-main">
				<div class="form-title">编辑公告</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>标题</div>
					<div class="input-item">
						<input type="text" name="title" class="form-control required-text w600" value="{$result['title']}" autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>分类</div>
					<div class="input-item">
						<select name="type" class="w100">
							<option value="-10"<if condition="$result['type'] eq -10"> selected</if>>分类</option>
							<option value="1"<if condition="$result['type'] eq 1"> selected</if>>项目制度</option>
							<option value="2"<if condition="$result['type'] eq 2"> selected</if>>公司制度</option>
							<option value="3"<if condition="$result['type'] eq 3"> selected</if>>信息发布</option>
							<option value="4"<if condition="$result['type'] eq 4"> selected</if>>通知</option>
							<option value="5"<if condition="$result['type'] eq 5"> selected</if>>其它</option>
						</select>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>针对用户</div>
					<div class="input-item">
						<label class="radio-inline"><input type="radio" name="is_all" value="1" <if condition="$result['is_all'] eq 1">checked</if> autocomplete="off">全部用户</label>
						<label class="radio-inline"><input type="radio" name="is_all" value="2" <if condition="$result['is_all'] eq 2">checked</if> autocomplete="off">选择用户</label>
						<span class="error-item">请选择用户</span>
						<div class="users-list"><if condition="$result['users'] neq NULL"><strong>已选用户：</strong>{$result['users']}</if></div>
						<input type="hidden" name="uids" class="uids-input" value="{$result['uids']}" autocomplete="off" />
						<input type="hidden" name="users" class="users-input" value="{$result['users']}" autocomplete="off" />
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">附件</div>
					<div class="input-item">
						<div class="input-group w250 left">
					    	<input type="text" name="file_name" class="form-control file-name" value="{$result['attachment_name']}" placeholder="请上传附件" <if condition="$result['attachment'] eq NULL">readonly</if> autocomplete="off">
				    		<span class="input-group-btn">
				        		<button class="btn file-submit" type="button">上传</button>
					    	</span>
					    </div>
					    <button <if condition="$result['attachment'] neq NULL">class="btn file-delete ml5"<else />class="btn file-delete ml5 hide"</if> type="button">删除</button>
					    <input type="hidden" name="file_url" class="file-url" value="{$result['attachment']}" autocomplete="off">
					    <span class="error-item">文件名必填</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>内容</div>
					<div class="input-item">
						<textarea name="content" class="form-control">{$result['content']}</textarea>
						<span class="error-item">必填项</span>
					</div>
				</div>
			</div>
			<div class="form-btn-item"><button class="btn sub" type="submit">提交</button><button class="btn btn-default goback" type="button">返回</button></div>
		</form>
	</div>
</div>
<!--选择用户-->
<div class="modal fade" id="selectuser-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>选择用户</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<foreach name="user_list" item="do">
					<div class="department">
						<label><input class="department-checkbox" type="checkbox" autocomplete="off" />{$do['name']}</label>
					</div>
					<ul>
						<foreach name="do['user']" item="uo">
							<li>
								<label><input class="user-checkbox" type="checkbox" value="{$uo['id']}" autocomplete="off" />{$uo['username']}</label>
							</li>
						</foreach>
					</ul>
				</foreach>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn user-affirm">确认</button><button type="button" class="btn btn-default user-cancel" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<!--/选择用户-->
<include file="Include:javascript" />
<script type="text/javascript" src="__PUBLIC__/js/user_select.js"></script>
<script type="text/javascript">
$(function(){
	KindEditor.ready(function(K){
		window.editor = K.create("[name='content']");
		//上传附件
		var editorFile = K.editor();
		$('.file-submit').on('click',function(){
			var parents = $(this).parents(".input-group");
			editorFile.loadPlugin('insertfile',function(){
				document.cookie="file_name=notice";
				document.cookie="file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt";
				editorFile.plugin.fileDialog({
					clickFn:function(url,title){
						parents.nextAll(".error-item").hide();
						parents.find(".file-name").val(title).prop("readonly",false);
						parents.nextAll(".file-url").val(url);
						parents.nextAll(".file-delete").show();
						editorFile.hideDialog();
					}
				});
			});
		});
	});

	//删除附件
	$(".file-delete").click(function(){
		$(this).hide();
		$(this).nextAll(".error-item").hide();
		$(this).nextAll(".file-url").val("");
		$(this).prevAll(".input-group").find(".file-name").val("").prop("readonly",true);
	});

	//用户选择
	$("[name='is_all']").click(function(){
		var $val = $("[name='is_all']:checked").val();

		if($val==2){
			$("#selectuser-modal").modal("show");
		}else{
			$(".users-list").html("");
			$("[name='uids'],[name='users']").val("");
		}
	});

	//表单验证
	$(".sub").click(function(){
		var tag = false;
		
		if($("[name='is_all']:checked").val()==2 && $(".uids-input").val()==""){
			$("[name='is_all']").parent().nextAll(".error-item").eq(0).show();
			tag = true;
		}
		$("[name='title']").each(function(){
			if($(this).val()==""){
				$(this).next(".error-item").show();
				tag = true;
			}
		});
		$("[name='type']").each(function(){
			if($(this).val()==-10){
				$(this).nextAll(".error-item").show();
				tag = true;
			}
		});
		if(editor.isEmpty()){
			$("[name='content']").next(".error-item").show();
			tag = true;
		}else{
			$("[name='content']").next(".error-item").hide();
		}

		$(".file-name").each(function(){
			var val = $(this).val();
			if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
				$(this).parents(".input-group").nextAll(".error-item").show();
				tag = true;
			}
		});
		
		if(tag){
			return false;
		}
	});
	
	//取消错误提示
	$("[name='is_all']").on("click",function(){
		$(this).parent().nextAll(".error-item").eq(0).hide();
	});
	$("[name='title']").focus(function(){
		$(this).next(".error-item").hide();
	});
	$(".file-name").on("focus",function(){
		$(this).parents(".input-group").nextAll(".error-item").hide();
	});
});
</script>
</body>
</html>